from dataclasses import dataclass, asdict
from typing import Dict

@dataclass
class ColorPalette:
    # 暗色系
    dark_one: str = ''
    dark_two: str = ''
    dark_three: str = ''
    dark_four: str = ''
    
    # 背景色
    bg_one: str = ''
    bg_two: str = ''
    bg_three: str = ''
    
    # 图标颜色
    icon_color: str = ''
    icon_hover: str = ''
    icon_pressed: str = ''
    icon_active: str = ''
    
    # 上下文颜色
    context_color: str = ''
    context_hover: str = ''
    context_pressed: str = ''
    
    # 文本颜色
    text_title: str = ''
    text_foreground: str = ''
    text_description: str = ''
    text_active: str = ''
    
    # 基础颜色
    white: str = ''
    pink: str = ''
    green: str = ''
    red: str = ''
    yellow: str = ''

    def update(self, new_colors: Dict[str, str]) -> None:
        """通过字典更新颜色值，忽略不存在的字段"""
        for key, value in new_colors.items():
            if hasattr(self, key):
                setattr(self, key, value)



    def to_dict(self) -> dict:
        """转换为字典格式"""
        return asdict(self)

    @classmethod
    def default_palette(cls) -> 'ColorPalette':
        """获取默认调色板实例"""
        return cls()